\NeedsTeXFormat{LaTeX2e}

\ProvidesPackage{localize}[2018/12/10 Package for localisation in LaTeX]


\RequirePackage{pgfkeys}


\DeclareRobustCommand{\setLocalisation}[3]{%
	% \setLocalisation{<ID>}{<language>}{<def>}
	\pgfkeyssetvalue{/localize/#2/#1}{#3}%
}

\DeclareRobustCommand{\setDefaultLocalisation}[2]{%
	% \setDefaultLocalisation{<ID>}{<def>}
	\pgfkeyssetvalue{/localize/defaults/#1}{#2}%
}

% Command for getting the localisation for the specified language
\DeclareRobustCommand{\getLocalisationFor}[2]{%
	\pgfkeysifdefined{/localize/#2/#1}{%
		\pgfkeysvalueof{/localize/#2/#1}%
	}{%
		\pgfkeysifdefined{/localize/defaults/#1}{%
			\pgfkeysvalueof{/localize/defaults/#1}%
		}{%
			\PackageError{localize}{There is no translation for the ID '#1' in the language '#2' and no default has been assigned for it}%
		}%
	}%
}

% Command for getting the localisation for the currently selected language
\DeclareRobustCommand{\getLocalisation}[1]{%
	% \getLocalisation{<ID>}
	\ifdef{\languagename}{%
		\getLocalisationFor{#1}{\languagename}%
	}{%
		\PackageError{localize}{Could not determine the set language - the languagename-macro from the babel-package is not set}%
	}%
}